package com.template.entity.markdown;


import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import static com.template.utlis.StringCommons.*;


/**
 * @author wangqi
 * @date 2024-01-17 15:53
 */
public class Table {
    private JSONArray jsonArray;
    private JSONObject header;

    public Table() {
        jsonArray = new JSONArray();
        header = new JSONObject();
    }

    public static Table create() {
        return new Table();
    }


    public JSONArray build() {
        return jsonArray;
    }

    public Table addMarkdownElement(MarkdownElement element) {
        if (element != null) {
            jsonArray.add(element.build());
        }
        return this;
    }

    public Table addColumnSet(ColumnSet columnSet) {
        if (columnSet != null) {
            jsonArray.add(columnSet.build());
        }
        return this;
    }


    public Table addUndefinedElement(JSONObject element) {
        if (element != null) {
            jsonArray.add(element);
        }
        return this;
    }

    public JSONObject getHeader() {
        return header;
    }

    public Table setHeaderTemplate(TemplateEnum template) {
        if (template != null) {
            header.put(TEMPLATE, template.getValue());
        }
        return this;
    }

    public Table setHeaderContent(String  content){
        JSONObject title = new JSONObject();
        title.put(CONTENT,translateContent(content));
        title.put(TAG,TagEnum.PLAIN_TEXT.getValue());
        header.put(TITLE,title);
        return this;
    }
}
